package com.camel.iamhi.entities;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.util.ObjectUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 参数
 *
 * @author camel
 */
@Data
public class IParams implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 返回属性列表
     **/
    private String fields;
    /**
     * 分页设定
     **/
    private Integer page;
    /**
     * 每页最大记录数
     **/
    private Integer pageSize;
    /**
     * 排序模式
     **/
    private String orderBy;
    /**
     * 过滤条件集合
     **/
    private List<IFilter> filters = new ArrayList<>();

    /**
     * 返回字段列表
     **/
    private String columns;

    /**
     * 分组
     **/
    private String groupBy;

    private String isValid;

    private JSONObject params;

    private boolean all;

    public Integer getPage() {
        return ObjectUtils.isEmpty(page) ? 1 : page;
    }

    public Integer getPageSize() {
        return ObjectUtils.isEmpty(pageSize) ? 10 : pageSize;
    }

    public boolean hasFilter(String fieldName) {
        for (IFilter filter : getFilters()) {
            if (filter.getFieldName().equals(fieldName)) {
                return true;
            }
        }
        return false;
    }

    public List<IFilter> getFilters() {
        return filters;
    }

    public void setFilters(List<IFilter> filters) {
        this.filters = filters;
    }

    public String getFields() {
        return fields;
    }

    public void setFields(String fields) {
        this.fields = fields;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getColumns() {
        return columns;
    }

    public void setColumns(String columns) {
        this.columns = columns;
    }

    public String getGroupBy() {
        return groupBy;
    }

    public void setGroupBy(String groupBy) {
        this.groupBy = groupBy;
    }

    public String getIsValid() {
        return isValid;
    }

    public void setIsValid(String isValid) {
        this.isValid = isValid;
    }

    public JSONObject getParams() {
        return params;
    }

    public void setParams(JSONObject params) {
        this.params = params;
    }

    public boolean isAll() {
        return all;
    }

    public void setAll(boolean all) {
        this.all = all;
    }
}
